package com.dataimport.utils;

import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder;
import com.dataimport.entity.targetentity.SchoolCalendar;
import com.dataimport.mapper.SchoolCalendarMapper;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class SchoolCalendarCache {
   public static Map<Object, Integer> selectSchoolCalendar(SchoolCalendarMapper schoolCalendarMapper){
        //查询mysql1 导出校历信息
        DynamicDataSourceContextHolder.push("mysql1");
        List<SchoolCalendar> schoolCalendars= schoolCalendarMapper.selectList(null);
        DynamicDataSourceContextHolder.poll();
//        校历信息放入缓存
        Map<Object, Integer>schoolCalendarCache=new HashMap<>();
        for (SchoolCalendar schoolCalendar : schoolCalendars) {
            schoolCalendarCache.put(schoolCalendar.getSchoolYear()+"-"+schoolCalendar.getSemester(), Math.toIntExact(schoolCalendar.getId()));
        }
        return schoolCalendarCache;
    }
}
